package com.yimi.policyservice.repository;

import com.yimi.policyservice.dto.policyaddr.IdsBean;
import com.yimi.policyservice.entity.base.system.SysRolePermission;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface SysRolePermissionRepository extends JpaRepository<SysRolePermission,String> {
    /**
     * 删除角色权限
     * @param id
     */
    @Modifying
    @Transactional
    @Query(value = "delete from t_sys_role_permission where role_id =?1 and type=?2",nativeQuery = true)
    void deleteByRoleId(String id,int type);

    /**
     * 查询角色下的菜单id
     * @param i
     * @param id
     * @return
     */
    @Query(value = "select p.menu_id from t_sys_role_permission p where p.type =?1 and p.role_id=?2",nativeQuery = true)
    List<String> findMenuIdByTypeAndRoleId(int i, String id);

    /**
     * 查询角色下的菜单id
     * @param type
     * @param id
     * @return
     */
    @Query(value = "select distinct p.permission_id from t_sys_role_permission p where p.type =?1 and p.role_id=?2",nativeQuery = true)
    List<String> findPermissionIdByTypeAndRoleId(int type, String id);
}
